/**
 * @file   ResponseStatus.cpp
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2014-04-26
 * @brief  DON response status enum and it's supporting functions.
 *
 * Copyright 2014  Djuro Drljaca (djurodrljaca@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <DON/Core/Packet/ResponseStatus.h>

using namespace DON::Core;

bool Packet::isResponseStatusValid(const ResponseStatus responseStatus)
{
    bool success = false;

    if ((responseStatus >= ResponseStatus_Success) &&
        (responseStatus <= ResponseStatus_ErrorCode255))
    {
        success = true;
    }

    return success;
}

Packet::ResponseStatus Packet::fromBinaryToResponseStatus(const char data)
{
    ResponseStatus responseStatus = ResponseStatus_Invalid;

    if ((data >= static_cast<char>(ResponseStatus_Success)) &&
        (data <= static_cast<char>(ResponseStatus_ErrorCode255)))
    {
        responseStatus = static_cast<ResponseStatus>(data);
    }

    return responseStatus;
}

char Packet::fromResponseStatusToBinary(const ResponseStatus responseStatus, bool *ok)
{
    char value = 0;
    bool success = false;

    if (isResponseStatusValid(responseStatus))
    {
        value = static_cast<char>(responseStatus);
        success = true;
    }

    if (ok != NULL)
    {
        *ok = success;
    }

    return value;
}
